<template>
	<view class="sub-money-content">
		<view class="home-top">
			<view class="home-title">邀请送现金</view>
			<image src="../../../static/common/sub-money-back.png" class="sub-back-icon" @tap="goHome"></image>
			<image src="../../../static/common/sbu-home-top-icon.png" class="sub-home-top-icon" @tap="contactKF"></image>
		</view>
		<view class="sub-bg">
			<image src="../../../static/common/sub-invite-bag.png" class="sub-bg-img-1"></image>
			<image src="../../../static/common/sub-invite-title.png" class="sub-bg-img-2"></image>
			<image src="../../../static/common/sub-invite-money.png" class="sub-bg-img-3"></image>
		</view>
		<view class="invite-friend">
			<image src="../../../static/common/red-bag.png" class="invite-frieds"></image>
		</view>
		<view class="invite-rules">
			<image src="../../../static/common/sub-make-money-times.png" class="invite-times"></image>
		</view>
		<view class="invite-red-bag">
			<view class="red-bag-item" @tap="openInviteTask(5,2,1)">
				<view class="red-bag-money-num">¥5</view>
				<view class="red-bag-invite-rule">邀请2人参与</view>
			</view>
			<view class="red-bag-item" @tap="openInviteTask(12.8,5,2)">
				<view class="red-bag-money-num">¥12.8</view>
				<view class="red-bag-invite-rule">邀请5人参与</view>
			</view>
		</view>
		<view class="invite-red-bag">
			<view class="red-bag-item" @tap="openInviteTask(20.8,8,3)">
				<view class="red-bag-money-num">¥20.8</view>
				<view class="red-bag-invite-rule">邀请8人参与</view>
			</view>
			<view class="red-bag-item" @tap="openInviteTask(28.8,10,4)">
				<view class="red-bag-money-num">¥28.8</view>
				<view class="red-bag-invite-rule">邀请10人参与</view>
			</view>
		</view>
		<view class="red-bag-blok">
			<navigator url="../sub-hongbao/sub-hongbao"><view>我的红包 >></view></navigator>
			<navigator url="../sub-rules/sub-rules" hover-class="none"><view>活动规则 >></view></navigator>
			
		</view>
		<view class="bottom-text">*添加右上角客服微信免费专属培训指导，疑问解答</view>
		
		<!-- 领取任务 -->
		<uni-popup ref="showshare" :type="type">
			<view class="uni-share">
				<view class="tip-block">
					<view class="money">￥{{money}}</view>
					<view class="text-t">现金红包</view>
					<view class="tips-text-t">开启后24小时内邀请{{person}}名新用户即可领取</view>
					<view class="btns">
						<view class="cancle-btn" @tap="cancel('share')">取消</view>
						<image src="../../../static/common/confirm-btn-m.png" class="confirm-btn" @tap="receive('share')"></image>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup  from'../../../components/uni-popup/uni-popup.vue'
	export default{
		name:"subMoney",
		data(){
			return{
				type: 'center',
				apptoken:"",
				money:"",
				person:"",
				taskType:""
			}
		},
		components:{
			uniPopup
		},
		onLoad() {
			this.apptoken = uni.getStorageSync('apptoken')
		},
		methods:{
			openInviteTask(m,p,t){
				this.money = m ;
				this.person = p ;
				this.taskType = t;
				this.$refs['showshare'].open();
			},
			receive(){
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.inviteTask,
					data:{ apptoken:this.apptoken,taskType:this.taskType },
					success(res) {
						console.log(res);
						if(res.data.success){
							let taskType = res.data.data.taskType;
							if(_this.taskType !== taskType){
								
								uni.showModal({
									title:"温馨提示",
									content:"当前有邀请任务未完成",
									confirmText:"查看任务",
									success(res) {
										if(res.confirm){
											uni.navigateTo({
												url:'../sub-makeInvite/sub-makeInvite?taskType='+taskType,
												success() {
													_this.$refs['showshare'].close();
												}
											})
										}
									}
								})
							}else{
								uni.navigateTo({
									url:'../sub-makeInvite/sub-makeInvite?taskType='+taskType
								})
							}
							
						}else{
							_this.$CommonJS.showToast(res.data.msg)
						}
					}
				})
			},
			goHome(){
				uni.navigateBack()
			},
			contactKF(type){
				this.$refs['show' + type].close();
				this.$CommonJS.navigateTo('../sub-kefu/sub-kefu')
			},
			cancel(type) {
				this.$refs['show' + type].close();
			},
		}
	}
</script>

<style scoped>
	@import url("sub-makeMoney.css");
</style>
